<script setup lang="ts">
import { getAchievTransList } from "@/api/research/achievTrans"; // 成果转化
import { getOtherAwardList } from "@/api/research/award"; // 科研获奖
import { getPaperList } from "@/api/research/paper"; // 论文
import { getPatentList } from "@/api/research/patent"; // 专利
import { getProjectList } from "@/api/research/project"; // 横向、纵向项目
import { getUserDetail } from "@/api/system/user";
import { formatDate } from "@/utils/common";
import ShowAchiev from "@/views/team/research/components/ShowAchiev.vue";
import { onMounted, ref } from "vue";

// 传值
const props = defineProps({
  //  1: 新增 2: 编辑
  id: {
    type: Number,
    default: null
  }
});
const form = ref<any>({});
const projectForm = ref({});
const loadProject = ref(false);
const loadProjectList = async userId => {
  loadProject.value = true;
  let params = {
    orderBy: "desc",
    userId: userId,
    pageNum: 1,
    pageSize: 999
  };
  let reqList = [];
  reqList.push(getProjectList({ projectType: 2, ...params })); // 项目类型 1纵向 2横向
  reqList.push(getProjectList({ projectType: 1, ...params })); // 项目类型 1纵向 2横向
  reqList.push(getPaperList(params));
  reqList.push(getPatentList(params));
  reqList.push(getOtherAwardList(params));
  reqList.push(getAchievTransList(params));

  let resArr = await Promise.all(reqList);
  console.log("resArr", resArr);

  // 封装请求回来的数据
  let tempForm: any = {};
  tempForm.id = 1;
  tempForm.horizontalProjects = resArr[0]?.data?.records || [];
  tempForm.longitudinalProjects = resArr[1]?.data?.records || [];
  tempForm.papers = resArr[2]?.data?.records || [];
  tempForm.patents = resArr[3]?.data?.records || [];
  tempForm.otherObtainRewards = resArr[4]?.data?.records || [];
  tempForm.transformations = resArr[5]?.data?.records || [];
  projectForm.value = tempForm;
  loadProject.value = false;
};

onMounted(() => {
  if (props.id) {
    getUserDetail({ id: props.id }).then(res => {
      form.value = res.data;
    });
    loadProjectList(props.id);
  }
});
</script>

<template>
  <div>
    <el-form :model="form" :inline="true" class="add-form" label-width="110px">
      <el-form-item label="姓名" prop="name">
        <div>{{ form.name || "--" }}</div>
      </el-form-item>
      <el-form-item label="工号" prop="number">
        <div>{{ form.number || "--" }}</div>
      </el-form-item>
      <el-form-item label="所属学院" prop="college">
        <div>{{ form.college || "--" }}</div>
      </el-form-item>
      <el-form-item label="所属系" prop="collegeSystem">
        <div>{{ form.collegeSystem || "--" }}</div>
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <div>{{ form.phone || "--" }}</div>
      </el-form-item>
      <el-form-item />
      <el-form-item label="电子邮箱" prop="email">
        <div>{{ form.email || "--" }}</div>
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <div>{{ form.sex == 1 ? "男" : form.sex == 2 ? "女" : "--" }}</div>
      </el-form-item>
      <el-form-item label="民族" prop="nationality">
        <div>{{ form.nationality || "--" }}</div>
      </el-form-item>
      <el-form-item label="出生年月" prop="birthday">
        <div>{{ formatDate(form.birthday, "--") }}</div>
      </el-form-item>
      <el-form-item label="学位" prop="degree">
        <div>{{ form.degree || "--" }}</div>
      </el-form-item>
      <el-form-item label="学历" prop="background">
        <div>{{ form.background || "--" }}</div>
      </el-form-item>
      <el-form-item label="职称" prop="titleNameList">
        <div>
          {{
            form.titleNameList && form.titleNameList.length > 0
              ? form.titleNameList.join(",")
              : "--"
          }}
        </div>
      </el-form-item>
      <el-form-item label="职务" prop="position">
        <div>{{ form.position || "--" }}</div>
      </el-form-item>
      <el-form-item label="研究方向与计划" prop="direction">
        <div>{{ form.direction || "--" }}</div>
      </el-form-item>
      <el-form-item />
      <el-form-item label="用户类型" prop="bizType">
        <div>
          {{
            form.userType == 2
              ? "超级管理员"
              : form.userType == 1
                ? "普通管理员"
                : "教师"
          }}
        </div>
      </el-form-item>
      <el-form-item label="人员构成" prop="bizType">
        <div>
          {{
            form.bizType == 1
              ? "校内人员"
              : form.bizType == 2
                ? "校外人员"
                : "--"
          }}
        </div>
      </el-form-item>
      <el-form-item />
    </el-form>
    <!-- 科研成果 -->
    <el-card v-loading="loadProject" class="kycg" shadow="always">
      <ShowAchiev :moduleData="projectForm" listMaxHeight="500px" />
    </el-card>
  </div>
</template>
<style lang="scss" scoped>
.add-form {
  text-align: center;
  margin-bottom: -15px;
  .el-form-item {
    width: 42%;
    margin-bottom: 5px;
  }
}
.kycg {
  margin: 10px 10px 20px;
}
</style>
